home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / memmove.s < prev    next >
Text File  |  1990-11-23  |  1KB  |  53 lines

  1. *    char *memmove(dest, source, len)
  2. *        register char *dest;
  3. *        register char *source;
  4. *        register unsigned int len;
  5. *    /*
  6. *     *    Copies the <source> block to the <dest>.  <len> bytes are
  7. *     *    always copied.  No terminator is added to <dest>.  A pointer
  8. *     *    to <dest> is returned.  Overlapping blocks ARE copied safely.
  9. *     */
  10. *        {
  11. *        register char *p = dest;
  12. *    
  13. *        if(source < dest)
  14. *            {
  15. *            dest += len;
  16. *            source += len;
  17. *            while(len--)
  18. *                *--dest = *--source;
  19. *            }
  20. *        else
  21. *            {
  22. *            while(len--)
  23. *                *dest++ = *source++;
  24. *            }
  25. *        return(p);
  26. *        }
  27.  
  28. .text
  29. .globl _memmove
  30. _memmove:
  31.     clr.l    d0
  32.     move.w    12(a7),d0    ; number of bytes
  33. memmove0:
  34.     move.l    4(a7),a1    ; destination
  35.     move.l    8(a7),a0    ; source
  36.     cmp.l    a0,a1        ; check copy direction
  37.     bls    memmove4
  38.     add.l    d0,a0        ; move pointers to end
  39.     add.l    d0,a1
  40.     bra    memmove2
  41. memmove1:
  42.     move.b    -(a0),-(a1)    ; (s < d) copy loop
  43. memmove2:
  44.     dbra    d0,memmove1
  45.     bra    memmove5
  46. memmove3:
  47.     move.b    (a0)+,(a1)+    ; (s >= d) copy loop
  48. memmove4:
  49.     dbra    d0,memmove3
  50. memmove5:
  51.     move.l    4(a7),d0    ; return destination pointer
  52.     rts
  53.